//package com.jzo2o.orders.manager.strategy.impl;
//
//import cn.hutool.core.bean.BeanUtil;
//import com.jzo2o.api.trade.enums.RefundStatusEnum;
//import com.jzo2o.orders.base.config.OrderStateMachine;
//import com.jzo2o.orders.base.enums.OrderStatusChangeEventEnum;
//import com.jzo2o.orders.base.enums.OrderStatusEnum;
//import com.jzo2o.orders.base.model.domain.OrdersCanceled;
//import com.jzo2o.orders.base.model.domain.OrdersRefund;
//import com.jzo2o.orders.base.model.dto.OrderSnapshotDTO;
//import com.jzo2o.orders.manager.model.dto.OrderCancelDTO;
//import com.jzo2o.orders.manager.service.IOrdersCanceledService;
//import com.jzo2o.orders.manager.service.IOrdersRefundService;
//import com.jzo2o.orders.manager.service.IOrdersServeManagerService;
//import com.jzo2o.orders.manager.strategy.OrderCancelStrategy;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.time.LocalDateTime;
//
///**
// * 运营端待评价状态取消订单
// *
// * @author itcast
// * @create 2023/8/7 17:10
// **/
//@Component("4:NO_EVALUATION")
//public class OperationNoEvaluationOrderCancelStrategy implements OrderCancelStrategy {
//    @Resource
//    private OrderStateMachine orderStateMachine;
//    @Resource
//    private IOrdersServeManagerService ordersServeManagerService;
//    @Resource
//    private IOrdersCanceledService ordersCanceledService;
//    @Resource
//    private IOrdersRefundService ordersRefundService;
//
//    /**
//     * 订单取消
//     *
//     * @param orderCancelDTO 订单取消模型
//     */
//    @Override
//    public void cancel(OrderCancelDTO orderCancelDTO) {
//        //1.状态机更新订单状态
//        OrderSnapshotDTO orderSnapshotDTO = OrderSnapshotDTO.builder()
//                .refundStatus(RefundStatusEnum.SENDING.getCode())
//                .cancellerId(orderCancelDTO.getCurrentUserId())
//                .cancelerName(orderCancelDTO.getCurrentUserName())
//                .cancellerType(orderCancelDTO.getCurrentUserType())
//                .cancelReason(orderCancelDTO.getCancelReason())
//                .cancelTime(LocalDateTime.now())
//                .build();
//
//        //2.保存订单取消记录
//        OrdersCanceled ordersCanceled = BeanUtil.toBean(orderSnapshotDTO, OrdersCanceled.class);
//        ordersCanceled.setId(orderCancelDTO.getId());
//        ordersCanceledService.save(ordersCanceled);
//
//        //3.订单状态变更
//        orderStateMachine.changeStatus(orderCancelDTO.getUserId(), orderCancelDTO.getId().toString(), OrderStatusChangeEventEnum.CLOSE_NO_EVALUATION_ORDER, orderSnapshotDTO);
//
//        //4.取消服务单
//        ordersServeManagerService.cancelByUserAndOperation(orderCancelDTO.getId());
//
//        //5.存入退款表，定时任务扫描进行退款
//        OrdersRefund ordersRefund = new OrdersRefund();
//        ordersRefund.setId(orderCancelDTO.getId());
//        ordersRefund.setTradingOrderNo(orderCancelDTO.getTradingOrderNo());
//        ordersRefund.setRealPayAmount(orderCancelDTO.getRealPayAmount());
//        ordersRefundService.save(ordersRefund);
//    }
//}
